import java.util.Arrays;
import java.util.Scanner;

public class Main33 {
    //33、做一个公司职员薪水管理系统，要求完成如下功能：
    //当有新员工时，将该员工加入到管理系统；
    //（1）可以根据员工号，显示该员工的信息；
    //（2）可以显示所有员工信息；
    //（3）可以修改员工薪水；
    //（4）当员工离职时，将该员工从管理系统中删除。
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        staff ss = new staff();
        staff[] staff = new staff[100];

        for (int i = 0; i < 10; i++) {
            System.out.println("请输入员工号");
            String staffId = scanner.next();
            System.out.println("请输入员工姓名");
            String name = scanner.next();
            System.out.println("请输入员工性别");
            String sex = scanner.next();
            System.out.println("请输入员工薪水");
            double salary = scanner.nextDouble();
            staff s = new staff(staffId,name,sex,salary);
            staff[i] = s;
        }

        ss.findStaff(staff,"1");
        ss.setSalary(staff[0],100);
        ss.showAll(staff);
        ss.delStaff(staff,"2");

    }
}

class staff{
    String staffId;
    String name;
    String sex;
    double salary;

    public staff() {
    }

    public staff(String staffId, String name, String sex, double salary) {
        this.staffId = staffId;
        this.name = name;
        this.sex = sex;
        this.salary = salary;
    }

    public void setSalary(staff s,double salary) {
        s.salary = salary;
    }

    public void findStaff(staff[] staff,String id){
        boolean flag = true;
        for (staff s : staff){
            if(s.staffId.equals(id)){
                flag = false;
                s.show();
                break;
            }
        }
        if (flag){
            System.out.println("不存在这个员工号为" + id + "的员工");
        }
    }


    public void show() {
        System.out.println( "staff{" +
                "staffId='" + staffId + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", salary=" + salary +
                '}');
    }

    public void showAll(staff[] staff){
        for (staff s : staff){
            if(s!=null) {
                s.show();
            }
        }
    }

    public void delStaff(staff[] staff,String id){
        boolean flag = true;
        for (int i = 0; i < staff.length; i++) {
            if(staff[i].staffId.equals(id)){
                for (int j = i; j < staff.length - 1; j++) {
                    staff[j] = staff[j+1];
                }
                flag = false;
                staff[staff.length-1]=null;
                System.out.println("删除成功");
                break;
            }
        }
        if (flag) {
            System.out.println("不存在这个员工号为" + id + "的员工");
        }
    }
}
